package com.ruoyi.wq.service.impl;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.Condition;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.wq.domain.WqQun;
import com.ruoyi.wq.domain.vo.WqQunVO;
import com.ruoyi.wq.mapper.WqQunMapper;
import com.ruoyi.wq.service.IWqQunService;

import cn.hutool.core.date.DateUtil;

/**
 * 砍价群Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-08-09
 */
@Service
public class WqQunServiceImpl extends ServiceImpl<WqQunMapper, WqQun> implements IWqQunService {
    
	@Autowired
    private WqQunMapper wqQunMapper;

    /**
     * 查询砍价群
     * 
     * @param id 砍价群主键
     * @return 砍价群
     */
    @Override
    public WqQun selectWqQunById(String id)
    {
        return wqQunMapper.selectWqQunById(id);
    }

    /**
     * 查询砍价群列表
     * 
     * @param wqQun 砍价群
     * @return 砍价群
     */
    @Override
    public List<WqQun> selectWqQunList(WqQun wqQun)
    {
        return wqQunMapper.selectWqQunList(wqQun);
    }

    /**
     * 新增砍价群
     * 
     * @param wqQun 砍价群
     * @return 结果
     */
    @Override
    public int insertWqQun(WqQun wqQun)
    {
        wqQun.setCreateTime(DateUtils.getNowDate());
        return wqQunMapper.insertWqQun(wqQun);
    }

    /**
     * 修改砍价群
     * 
     * @param wqQun 砍价群
     * @return 结果
     */
    @Override
    public int updateWqQun(WqQun wqQun)
    {
        wqQun.setUpdateTime(DateUtils.getNowDate());
        return wqQunMapper.updateWqQun(wqQun);
    }

    /**
     * 批量删除砍价群
     * 
     * @param ids 需要删除的砍价群主键
     * @return 结果
     */
    @Override
    public int deleteWqQunByIds(String[] ids)
    {
        return wqQunMapper.deleteWqQunByIds(ids);
    }

    /**
     * 删除砍价群信息
     * 
     * @param id 砍价群主键
     * @return 结果
     */
    @Override
    public int deleteWqQunById(String id)
    {
        return wqQunMapper.deleteWqQunById(id);
    }

	@Override
	public TableDataInfo getPageList(WqQun wqQun) {
		IPage<WqQunVO> page = baseMapper.selectPageList(Condition.getPage(wqQun), wqQun);
		for(WqQunVO vo : page.getRecords()){
			vo.setPubDate(DateUtil.formatDate(vo.getCreateTime()));
		}
		return Condition.getTableDataInfo(page.getRecords(), page.getTotal());
	}

	@Override
	public WqQunVO getQunById(String id) {
		WqQun qun = baseMapper.selectById(id);
		WqQunVO vo = new WqQunVO();
		BeanUtils.copyProperties(qun, vo, WqQunVO.class);
		vo.setPubDate(DateUtil.formatDate(vo.getCreateTime()));
		return vo;
	}
}
